package com.qf.service;

import com.qf.dao.UserDao;
import com.qf.dao.UserDaoImpl1;
import com.qf.pojo.User;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/2 9:34
 */
public class UserServiceImpl1 implements UserService {


    //注入全局属性
    private UserDao userDao;


    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        System.out.println("======UserServiceImpl1的set注入方法执行===========");
        this.userDao = userDao;
    }

    /**
     * 无参数构造方法
     */
    public UserServiceImpl1() {
        System.out.println("=======UserServiceImpl1执行构造======");
    }

    /**
     * 初始化
     */
    @PostConstruct
    public void init() {
        System.out.println("===UserServiceImpl1初始化init=====");
    }

    /**
     * 销毁
     */
    @PreDestroy
    public void destroy() {
        System.out.println("====UserServiceImpl1销毁 destroy=========");
    }

    /**
     * 业务方法
     */

    public void registUser() {
       UserDao userDao = new UserDaoImpl1();
       userDao.insertUser();
        System.out.println("======UserService接口的第一种实现类============");
    }

    public List<User> findUserAll() {
        System.out.println("======UserServiceImpl执行了findUserAll方法============");
        return new ArrayList<User>();
    }

    public void insertUser(User user) {

         System.out.println("======UserServiceImpl执行了insertUser方法============");
    }

    public void updateUser(User user) {
        System.out.println("======UserServiceImpl执行了updateUser方法============");

    }

    @Override
    public void deleteUser(Integer id) {
        System.out.println("======UserServiceImpl执行了deleteUser方法============");
        //模拟发生异常
        int i =1/0;
    }
}
